-
Notifications
You must be signed in to change notification settings - Fork 15
Divide project into library and binary parts #112
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
9e75b95 to
2c4c4bd
Compare
|
|
||
| [features] | ||
| watch = ["spirv-builder/watch"] | ||
| clap = ["dep:clap", "spirv-builder/clap"] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would a little comment here describing the clap-the-feature, be useful here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I agree a little note would be good.
|
So this allows using |
| @@ -89,6 +101,7 @@ impl Build { | |||
| std::env::current_dir()?.display() | |||
| ); | |||
|
|
|||
| #[cfg(feature = "watch")] | |||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We need to restructure this to handle the case where the watch feature is disabled to let the else case happen. I'm pretty sure that with this change if the watch feature is missing the entire if else won't be compiled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something like:
#[cfg(feature = "watch")]
let watching = self.build.watch;
#[cfg(not(feature = "watch"))]
let watching = false;
if watching {
...
} else {
...
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with that, I'll rewrite this code soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main difficulty here is not the flag itself, but the code inside of is watching block, which is valid only if watch feature of spirv-builder is enabled.
I really want to move this logic inside of private method to not to clutter run method with conditional compilation handling.
crates/cargo-gpu/src/build.rs
Outdated
| Ok(()) | ||
| } | ||
|
|
||
| /// Parses compilation result from `SpirvBuilder` and writes it out to a file | ||
| #[cfg(feature = "watch")] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we want this cfg here, because we still want to parse compilation results if we're not watching.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I placed this just because this was marked by linter as unused (because I've cfg-featured the code block above).
Rewriting an if above with removing this cfg will resolve it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just needs a few tweaks to the cfg stuff. Good work!
It is already possible on |
crates/cargo-gpu-cache/src/build.rs
Outdated
| if let Some(accept) = accept { | ||
| accept.submit(result1); | ||
| accept.submit(parse_result); | ||
| } | ||
| })? | ||
| .context("unreachable")??; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have a strong feeling that this line means watch method should return ! or anyhow::Result<!>, but I'm not sure which one was in mind when this code were written.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Without looking at the code I'm thinking it makes most sense to use anyhow::Result<!>. Conceptually, watching is a never-ending loop, and there could be errors along the way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, I see, that's on SpirvBuilder...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it looks like SpirvBuilder spawns a thread and calls the given callback with the compilation result. But it doesn't look like there's any way to know when/if that spawned thread exits. It seems expected we loop forever until the user exits explicitly (hits control-c), so I don't think SpirvBuilder::watch needs to communicate anything, and I think we can provide the anyhow::Result<!> in our watch function by doing:
loop {
std::thread::park();
}@tombh, @Firestar99 how do you two feel about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even though I originally added the watch code in cargo-gpu I don't remember all of the failure cases I'm afraid. I do personally use --watch often and it works well (just a small annoyance that it compiles twice on first run). So all I'd want to see is that the compilation logs still display and that CTRL+C exits.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think in practice the loop above should never actually loop, as thread::park should never return. But the loopgives us the return type we want.
I haven't actually written any of this code I'm suggesting though, so the real compiler (as opposed to my head compiler) might have something else to say about it ;).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I noticed that if shader crate compiles with errors in the first time, it returns an error, so it cannot be anyhow::Result<!>.
I also decided to turn panics into errors.
I removed loop and thread park entirely: I don't know if this behavior is Windows-specific, but watching continued without explicit waiting.
Additionally, I have a feeling that watch could return JoinHandle or its wrapper to the caller. Then we could just join it inside of this private method and return an error if watching ends somehow.
This is impossible to do, because But we can return JoinHandle<!> cannot be returned.Infallible, which hopefully will be the never type after its stabilization.
I've made a PR for that.
|
Also I'm not sure about APIs of library and binary parts:
This could be resolved in some separate PR, but I think this needs to be addressed at least. |
|
I'll try to reorder commits of this branch via rebase now to de-clutter merge history. P.S.: success! 🎊 |
a29f17d to
b541ec6
Compare
I think it would be nice to add |
|
Certainly a separate PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So far so good, we just need to address the feature comment and the watch situation. Thank you!
|
Wait what, how did I miss this one? Will have a look tomorrow morning. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One huge red flag: We cannot rename the cli tool. It must stay cargo-gpu, otherwise you'd have to call it with cargo gpu-cli instead of just cargo gpu (iirc). Especially since we want to (more strongly) mirror cargo commands in the future, like cargo gpu check or cargo gpu clippy.
Otherwise, I strongly support the split up. I just haven't gotten around to it, or figured out a good alternative name for the "cargo-gpu-lib". Some ideas, feel free to suggest more:
- rustc_codegen_spirv_cache
- cargo_gpu_cache
- rust_gpu_cache
The binary is still |
I would just make most of it |
|
In case it is useful as a reference, here is the minimal API I'm using right now: let backend = cargo_gpu::Install::from_shader_crate(shader_crate.clone()).run()?;
let spirv_builder = backend
.to_spirv_builder(shader_crate, "spirv-unknown-vulkan1.2")Plus P.S. Noticed just now that for some reason path to shader crate ( The goal in the issue #105 was to remove dependencies from the library crate. This PR is a step in the right direction, which makes dependencies optional. But it still doesn't remove them, which causes interesting side-effects when Cargo's feature unification kicks in. So I'd say eventually those dependencies should be removed, which likely means all data structures that depend on them (like CLI arguments/options) will need to move as well. |
I honestly do not want to rename |
Inside of my project (which I mentioned in #93) I moved to |
This comment was marked as off-topic.
This comment was marked as off-topic.
|
So long as Thanks for your great work @tuguzT! |
b541ec6 to
d3026f8
Compare
I think The former suits because, as stated in README,
The latter - because P.S.: also these names could contain But for now, I prefer |
|
Another point against This means that |
This comment was marked as outdated.
This comment was marked as outdated.
7dce50f to
a01cb15
Compare
This comment was marked as outdated.
This comment was marked as outdated.
c9419ef to
89d5713
Compare
ababc64 to
8954b47
Compare
|
Have you changed something CI related that lints is failing, or is it just failing in general? (I'll go fix it if it's on us) |
This comment was marked as outdated.
This comment was marked as outdated.
|
I've moved reworked, more aggressive lib/bin split in a separate draft, #117 |
76282f1 to
30747ac
Compare
Fixes #105